package com.chen.mobiletwo.controller;

import com.chen.mobiletwo.entity.ResultEntity;
import com.chen.mobiletwo.service.StudentService;
import jakarta.annotation.Resource;
import org.apache.ibatis.annotations.Delete;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@CrossOrigin//跨域
@RestController//遵循RestFul
@RequestMapping("v2/Student/")
public class StudentController {
   // private static final Logger logger= LoggerFactory.getLogger(StudentController.class);//日志getLogger需要传入的类名
    @Resource
    private RedisTemplate<String ,String> redisTemplate;//Redis工具类
    @Resource
    StudentService studentService;

    /**
     * 删除学生
     * @param stuId 学生id
     * @return json
     */
    @DeleteMapping("delStudent")
    private String delStudent(@RequestParam(value = "stuId",defaultValue = "-1") int stuId){
        if (stuId==-1){
            return ResultEntity.fail(-10002);
        }
        return studentService.delStudent(stuId);
    }

    /**
     * 删除学生详情（硬删除）
     *  @param stuId 学生id
     *  @return json
     */
    @DeleteMapping("delStudentDetail")
    private String delStudentDetail(@RequestParam(value = "stuId",defaultValue = "-1") int stuId){
        if (stuId==-1){
            return ResultEntity.fail(-10002);
        }
        return studentService.delStudentDetail(stuId);
    }
    /**
     * 删除用户（软删除）
     * @param stuId 学生id
     * @return json
     */
    @DeleteMapping("delStudentIsDel")
    private String delStudentIsDel(@RequestParam(value = "stuId",defaultValue = "-1") int stuId){
        if (stuId==-1){
            return ResultEntity.fail(-10002);
        }
        return studentService.delStudentIsDel(stuId);
    }
    /**
     * 修改在校状态
     * @param inScl 是否在校 0：在校 1：离校
     * @param stuId 学生id
     * @return json
     */
    @PutMapping("upIsScl")
    private String upIsScl(@RequestParam(value = "inScl",defaultValue = "-1") int inScl,
                           @RequestParam(value = "stuId",defaultValue = "-1") int stuId
                           ){
        if (stuId==-1||inScl==-1){
            return ResultEntity.fail(-10002);
        }
        return studentService.upIsScl(inScl,stuId);
    }
    /**
     * 根据stuid修改学生基本信息
     * @param name 学生姓名
     * @param stuId 学生id
     * @return json
     */
    @PutMapping("upStudentByStuId")
    private String upStudentByStuId(@RequestParam(value = "name",defaultValue = "-1") String name,
                                    @RequestParam(value = "stuId",defaultValue = "-1") int stuId){
        if (stuId==-1||name.equals("")){
            return ResultEntity.fail(-10002);
        }
        return studentService.upStudentByStuId(name,stuId);
    }
    /**
     * 根据stuid修改学生详情
     * @param email 邮箱
     * @param sex 性别 0：男 1：女
     * @param sfzId 身份证
     * @param phone 手机号
     * @param weChat 微信号
     * @param stuId 学生id
     * @return json
     */
    @PutMapping("upStudentDetailByStuId")
    private String upStudentDetailByStuId(
            @RequestParam(value = "email",defaultValue = "-1") String email,
            @RequestParam(value = "sex",defaultValue = "-1") int sex,
            @RequestParam(value = "sfzId",defaultValue = "-1") String sfzId,
            @RequestParam(value = "phone",defaultValue = "-1") String phone,
            @RequestParam(value = "weChat",defaultValue = "-1") String weChat,
            @RequestParam(value = "stuId",defaultValue = "-1") int stuId){
        if (stuId==-1||email.equals("")||sex==-1||sfzId.equals("")||phone.equals("")||weChat.equals("")){
            return ResultEntity.fail(-10002);
        }
        return studentService.upStudentDetailByStuId(email,sex,sfzId,phone,weChat,stuId);
    }

    /**
     * 添加学生
     * @param name 学生姓名
     * @return json
     */
    @PostMapping("addStudent")
    private String addStudent(@RequestParam(value = "name",defaultValue = "-1") String name){
        if (name.equals("")){
            return ResultEntity.fail(-10002);
        }
        return studentService.addStudent(name);
    }
    /**
     * 添加学生学生详情信息
     * @param stuId 学生id
     * @param email 邮箱号
     * @param sex 性别
     * @param sfzId 身份证
     * @param phone 手机号
     * @param weChat 微信号
     * @return json
     */
    @PostMapping("addStudentDetail")
        private String addStudentDetail(
            @RequestParam(value = "stuId",defaultValue = "-1") int stuId,
            @RequestParam(value = "email",defaultValue = "-1") String email,
            @RequestParam(value = "sex",defaultValue = "-1") int sex,
            @RequestParam(value = "sfzId",defaultValue = "-1") String sfzId,
            @RequestParam(value = "phone",defaultValue = "-1") String phone,
            @RequestParam(value = "weChat",defaultValue = "-1") String weChat
            ){
        if (stuId==-1||email.equals("")||sex==-1||sfzId.equals("")||phone.equals("")||weChat.equals("")){
            return ResultEntity.fail(-10002);
        }
        return studentService.addStudentDetail(stuId,email,sex,sfzId,phone,weChat);
    }
    /**
     * 根据视图查询所有信息
     * @return json
     */
    @GetMapping("getStudentViewList")
    private String getStudentViewList(){
        return studentService.getStudentViewList();
    }
    /**
     * 根据stuid查询学生详情信息
     * @param stuId 学生id
     * @return json
     */
    @GetMapping("getStudentByStuId")
    private String getStudentByStuId(@RequestParam(value = "stuId",defaultValue = "-1") int stuId){
        if (stuId==-1){
            return ResultEntity.fail(-10002);
        }
        return studentService.getStudentByStuId(stuId);
    }
    /**
     * 根据stuid查询学生详情信息
     * @param stuId 学生id
     * @return json
     */
    @GetMapping("getStudentDetailByStuId")
    private String getStudentDetailByStuId(@RequestParam(value = "stuId",defaultValue = "-1") int stuId){
        if (stuId==-1){
            return ResultEntity.fail(-10002);
        }
        return studentService.getStudentDetailByStuId(stuId);
    }
}
